/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * IjinInsidentilDialog.java
 *
 * Created on Oct 2, 2011, 7:41:38 PM
 */
package com.x3.dishub.ui;

import com.x3.dishub.dao.IjinInsidentilDAO;
import com.x3.dishub.dao.KartuPengawasanOtobisUmumDAO;
import com.x3.dishub.dao.KendaraanDAO;
import com.x3.dishub.dao.PerusahaanDAO;
import com.x3.dishub.dao.WarnaDAO;
import com.x3.dishub.entity.IjinInsidentil;
import com.x3.dishub.entity.KartuPengawasanOtobisUmum;
import com.x3.dishub.entity.Kendaraan;
import com.x3.dishub.entity.Perusahaan;
import com.x3.dishub.entity.Warna;
import java.awt.Color;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.sql.DataSource;
import javax.swing.JColorChooser;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JRViewer;

/**
 *
 * @author Hendro Steven
 */
public class IjinInsidentilDialog extends javax.swing.JDialog {

    private WarnaDAO wDao = (WarnaDAO) MainApps.appContext.getBean("warnaDAO");
    private Warna headerColor;
    private Warna backgroudColor;

    private IjinInsidentilDAO dao = (IjinInsidentilDAO) MainApps.appContext.getBean("ijinInsidentilDAO");
    private List<IjinInsidentil> list;
    private IjinInsidentil selected;
    private PerusahaanDAO pDao = (PerusahaanDAO) MainApps.appContext.getBean("perusahaanDAO");
    private KartuPengawasanOtobisUmumDAO kDao = (KartuPengawasanOtobisUmumDAO) MainApps.appContext.getBean("kartuPengawasanOtobisUmumDAO");
    private List<Perusahaan> listPerusahaan;
    private Perusahaan perusahaan;
    private List<KartuPengawasanOtobisUmum> listKartuPengawasan;
    private KartuPengawasanOtobisUmum kartuPengawasan;
    private KendaraanDAO kenDao = (KendaraanDAO) MainApps.appContext.getBean("kendaraanDAO");
    private List<Kendaraan> listKendaraan;
    private Kendaraan kendaraan;
    private SimpleDateFormat formater = new SimpleDateFormat("dd/MM/yyyy");

    /** Creates new form IjinInsidentilDialog */
    public IjinInsidentilDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        this.setLocationRelativeTo(null);
        loadWarna();
        updateWarna();
        //this.getContentPane().setBackground(new java.awt.Color(51, 102, 255));
        reloadAll();
        loadPerusahaan();
    }

    private void loadWarna() {
        headerColor = wDao.getByNama("IjinInsidentilDialogHd");
        if (headerColor == null) {
            headerColor = new Warna();
            headerColor.setName("IjinInsidentilDialogHd");
            headerColor.setRgb(-16777012);
            wDao.insert(headerColor);
            loadWarna();
        }
        backgroudColor = wDao.getByNama("IjinInsidentilDialogBg");
        if (backgroudColor == null) {
            backgroudColor = new Warna();
            backgroudColor.setName("IjinInsidentilDialogBg");
            backgroudColor.setRgb(-13408513);
            wDao.insert(backgroudColor);
            loadWarna();
        }
    }

    private void updateWarna() {
        headerPanel.setBackground(new Color(headerColor.getRgb()));
        this.getContentPane().setBackground(new Color(backgroudColor.getRgb()));
    }

    private void reloadAll() {
        try {
            list = dao.getAllIjinInsidentil();
            bindIjin();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }

    private void bindIjin() {
        try {
            String title[] = {"Nomor", "No.Kendaraan", "Maksud Perjalanan", "Jumlah Penumpang", "Berakhir Tanggal"};
            Object[][] data = new Object[list.size()][5];
            int row = 0;
            for (IjinInsidentil i : list) {
                data[row][0] = i.getNomor();
                data[row][1] = i.getKendaraan().getNomorPolisi();
                data[row][2] = i.getMaksudPerjalanan();
                data[row][3] = i.getJumlahPenumpang();
                data[row][4] = formater.format(i.getBerlakuSampai());
                ++row;
            }
            TableModel model = new DefaultTableModel(data, title);
            tblIjin.setModel(model);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        browseKendaraan = new javax.swing.JDialog();
        jLabel22 = new javax.swing.JLabel();
        txtCariNomorPolisi = new javax.swing.JTextField();
        btnCariKendaraan1 = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        tblBrowseKendaraan = new javax.swing.JTable();
        browseKartuPengawasan = new javax.swing.JDialog();
        jLabel15 = new javax.swing.JLabel();
        txtNoKartuCari = new javax.swing.JTextField();
        btnCariKartu = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblKartu = new javax.swing.JTable();
        headerPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        tabpane = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblIjin = new javax.swing.JTable();
        btnCariNomor = new javax.swing.JButton();
        btnCariKendaraan = new javax.swing.JButton();
        btnRefresh = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        txtKapasitas = new javax.swing.JTextField();
        txtNomor = new javax.swing.JTextField();
        tglIjin = new org.jdesktop.swingx.JXDatePicker();
        cmbPerusahaan = new javax.swing.JComboBox();
        txtNoKendaraan = new javax.swing.JTextField();
        btnBrowseKendaraan = new javax.swing.JButton();
        txtKartuPengawasan = new javax.swing.JTextField();
        btnBrowseKartu = new javax.swing.JButton();
        txtNoUjiBerkala = new javax.swing.JTextField();
        txtMasaUjiBerkala = new javax.swing.JTextField();
        txtMaksud = new javax.swing.JTextField();
        tglBerlakuSampai = new org.jdesktop.swingx.JXDatePicker();
        txtJumlah = new javax.swing.JTextField();
        txtRute = new javax.swing.JTextField();
        btnSimpan = new javax.swing.JButton();
        btnBuat = new javax.swing.JButton();
        btnHapus = new javax.swing.JButton();
        btnCetak = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        mnuUbahWarna = new javax.swing.JMenu();
        mnuWarnaHeader = new javax.swing.JMenuItem();
        mnuWarnaBack = new javax.swing.JMenuItem();
        mnuWarnaDefault = new javax.swing.JMenuItem();

        jLabel22.setText("Nomor Polisi :");

        btnCariKendaraan1.setText("Cari");
        btnCariKendaraan1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariKendaraan1ActionPerformed(evt);
            }
        });

        tblBrowseKendaraan.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblBrowseKendaraan.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblBrowseKendaraanMouseClicked(evt);
            }
        });
        jScrollPane6.setViewportView(tblBrowseKendaraan);

        javax.swing.GroupLayout browseKendaraanLayout = new javax.swing.GroupLayout(browseKendaraan.getContentPane());
        browseKendaraan.getContentPane().setLayout(browseKendaraanLayout);
        browseKendaraanLayout.setHorizontalGroup(
            browseKendaraanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(browseKendaraanLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(browseKendaraanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 696, Short.MAX_VALUE)
                    .addGroup(browseKendaraanLayout.createSequentialGroup()
                        .addComponent(jLabel22)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtCariNomorPolisi, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCariKendaraan1)))
                .addContainerGap())
        );
        browseKendaraanLayout.setVerticalGroup(
            browseKendaraanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(browseKendaraanLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(browseKendaraanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel22)
                    .addComponent(txtCariNomorPolisi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCariKendaraan1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 409, Short.MAX_VALUE)
                .addContainerGap())
        );

        jLabel15.setText("Nomor :");

        btnCariKartu.setText("Cari");
        btnCariKartu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariKartuActionPerformed(evt);
            }
        });

        tblKartu.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblKartu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblKartuMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tblKartu);

        javax.swing.GroupLayout browseKartuPengawasanLayout = new javax.swing.GroupLayout(browseKartuPengawasan.getContentPane());
        browseKartuPengawasan.getContentPane().setLayout(browseKartuPengawasanLayout);
        browseKartuPengawasanLayout.setHorizontalGroup(
            browseKartuPengawasanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(browseKartuPengawasanLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(browseKartuPengawasanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 690, Short.MAX_VALUE)
                    .addGroup(browseKartuPengawasanLayout.createSequentialGroup()
                        .addComponent(jLabel15)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtNoKartuCari, javax.swing.GroupLayout.PREFERRED_SIZE, 241, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCariKartu)))
                .addContainerGap())
        );
        browseKartuPengawasanLayout.setVerticalGroup(
            browseKartuPengawasanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(browseKartuPengawasanLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(browseKartuPengawasanLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(txtNoKartuCari, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCariKartu))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Ijin Insidentil");

        headerPanel.setBackground(new java.awt.Color(0, 0, 204));
        headerPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 20));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("Ijin Insidentil");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12));
        jLabel2.setForeground(new java.awt.Color(255, 255, 255));
        jLabel2.setText("Pembuatan Ijin Insidentil");

        javax.swing.GroupLayout headerPanelLayout = new javax.swing.GroupLayout(headerPanel);
        headerPanel.setLayout(headerPanelLayout);
        headerPanelLayout.setHorizontalGroup(
            headerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(headerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(headerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(headerPanelLayout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(jLabel2))
                    .addComponent(jLabel1))
                .addContainerGap(729, Short.MAX_VALUE))
        );
        headerPanelLayout.setVerticalGroup(
            headerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(headerPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        tblIjin.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblIjin.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblIjinMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblIjin);

        btnCariNomor.setText("Cari Berdasarkan Nomor");
        btnCariNomor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariNomorActionPerformed(evt);
            }
        });

        btnCariKendaraan.setText("Cari Berdasarkan Kendaraan");
        btnCariKendaraan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCariKendaraanActionPerformed(evt);
            }
        });

        btnRefresh.setText("Refresh Tabel");
        btnRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRefreshActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 842, Short.MAX_VALUE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(btnCariNomor)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCariKendaraan)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 419, Short.MAX_VALUE)
                        .addComponent(btnRefresh)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 352, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCariNomor)
                    .addComponent(btnCariKendaraan)
                    .addComponent(btnRefresh))
                .addContainerGap())
        );

        tabpane.addTab("Daftar Ijin Insidentil", jPanel2);

        jLabel3.setText("Nomor :");

        jLabel4.setText("Tanggal :");

        jLabel5.setText("Perusahaan :");

        jLabel6.setText("No. Kendaraan :");

        jLabel7.setText("Kartu Pengawasan :");

        jLabel8.setText("No. Uji Berkala :");

        jLabel9.setText("Masa Berlaku Uji Berkala :");

        jLabel10.setText("Maksud Perjalanan :");

        jLabel11.setText("Kapasitas Tempat Duduk :");

        jLabel12.setText("Berlaku Sampai :");

        jLabel13.setText("Jumlah Penumpang :");

        jLabel14.setText("Rute Perjalanan :");

        cmbPerusahaan.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        txtNoKendaraan.setEditable(false);

        btnBrowseKendaraan.setText("....");
        btnBrowseKendaraan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBrowseKendaraanActionPerformed(evt);
            }
        });

        txtKartuPengawasan.setEditable(false);

        btnBrowseKartu.setText("....");
        btnBrowseKartu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBrowseKartuActionPerformed(evt);
            }
        });

        btnSimpan.setText("Simpan");
        btnSimpan.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSimpanActionPerformed(evt);
            }
        });

        btnBuat.setText("Buat Baru");
        btnBuat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuatActionPerformed(evt);
            }
        });

        btnHapus.setText("Hapus");
        btnHapus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnHapusActionPerformed(evt);
            }
        });

        btnCetak.setText("Cetak Ijin Insidentil");
        btnCetak.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCetakActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel8, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel9, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel10, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel11, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel12, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel13, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel14, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtMaksud, javax.swing.GroupLayout.PREFERRED_SIZE, 631, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtMasaUjiBerkala, javax.swing.GroupLayout.PREFERRED_SIZE, 271, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtJumlah, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(tglBerlakuSampai, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtNomor, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
                                    .addComponent(txtKapasitas, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(tglIjin, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGroup(jPanel3Layout.createSequentialGroup()
                                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addComponent(txtNoUjiBerkala, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtKartuPengawasan, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(txtNoKendaraan, javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(cmbPerusahaan, javax.swing.GroupLayout.Alignment.LEADING, 0, 302, Short.MAX_VALUE))
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(btnBrowseKartu)
                                        .addComponent(btnBrowseKendaraan)))
                                .addComponent(txtRute, javax.swing.GroupLayout.DEFAULT_SIZE, 631, Short.MAX_VALUE)))
                        .addGap(92, 92, 92))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                        .addComponent(btnCetak)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 496, Short.MAX_VALUE)
                        .addComponent(btnHapus)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnBuat)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSimpan)
                        .addContainerGap())))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(txtNomor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(tglIjin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(cmbPerusahaan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtNoKendaraan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBrowseKendaraan))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(txtKartuPengawasan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBrowseKartu))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtNoUjiBerkala, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(txtMasaUjiBerkala, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(txtMaksud, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(txtKapasitas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(tglBerlakuSampai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel13)
                    .addComponent(txtJumlah, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel14)
                    .addComponent(txtRute, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 47, Short.MAX_VALUE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSimpan)
                    .addComponent(btnBuat)
                    .addComponent(btnHapus)
                    .addComponent(btnCetak))
                .addContainerGap())
        );

        tabpane.addTab("Detail dan Buat Baru", jPanel3);

        mnuUbahWarna.setText("Seting");

        mnuWarnaHeader.setText("Warna Header");
        mnuWarnaHeader.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuWarnaHeaderActionPerformed(evt);
            }
        });
        mnuUbahWarna.add(mnuWarnaHeader);

        mnuWarnaBack.setText("Warna Backgroud");
        mnuWarnaBack.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuWarnaBackActionPerformed(evt);
            }
        });
        mnuUbahWarna.add(mnuWarnaBack);

        mnuWarnaDefault.setText("Warna Default");
        mnuWarnaDefault.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuWarnaDefaultActionPerformed(evt);
            }
        });
        mnuUbahWarna.add(mnuWarnaDefault);

        jMenuBar1.add(mnuUbahWarna);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(headerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(tabpane)
                .addGap(10, 10, 10))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(headerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tabpane, javax.swing.GroupLayout.DEFAULT_SIZE, 436, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCariNomorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariNomorActionPerformed
        try {
            list = dao.getByNomor(JOptionPane.showInputDialog(this, "Nomor :"));
            bindIjin();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_btnCariNomorActionPerformed

    private void btnCariKendaraan1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariKendaraan1ActionPerformed
        try {
            listKendaraan = kenDao.getByNomorPolisi(txtCariNomorPolisi.getText());
            String title[] = {"No. Polisi", "No.Uji", "Merk/Type", "Tahun"};
            Object[][] data = new Object[listKendaraan.size()][4];
            int row = 0;
            for (Kendaraan k : listKendaraan) {
                data[row][0] = k.getNomorPolisi();
                data[row][1] = k.getNomorUji();
                data[row][2] = k.getMerk() + k.getType();
                data[row][3] = k.getTahunPembuatan();
                ++row;
            }
            TableModel model = new DefaultTableModel(data, title);
            tblBrowseKendaraan.setModel(model);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
}//GEN-LAST:event_btnCariKendaraan1ActionPerformed

    private void tblBrowseKendaraanMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblBrowseKendaraanMouseClicked
        try {
            Kendaraan k = (Kendaraan) listKendaraan.get(tblBrowseKendaraan.getSelectedRow());
            if (isCari) {
                list = dao.getByKendaraan(k);
                bindIjin();
            } else {
                txtNoKendaraan.setText(k.getNomorPolisi());
                kendaraan = k;
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
        isCari = false;
        browseKendaraan.setVisible(false);
}//GEN-LAST:event_tblBrowseKendaraanMouseClicked
    boolean isCari;
    private void btnCariKendaraanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariKendaraanActionPerformed
        isCari = true;
        browseKendaraan();
    }//GEN-LAST:event_btnCariKendaraanActionPerformed

    private void browseKendaraan() {
        try {
            listKendaraan = kenDao.getAll();
            String title[] = {"No. Polisi", "No.Uji", "Merk/Type", "Tahun"};
            Object[][] data = new Object[listKendaraan.size()][4];
            int row = 0;
            for (Kendaraan k : listKendaraan) {
                data[row][0] = k.getNomorPolisi();
                data[row][1] = k.getNomorUji();
                data[row][2] = k.getMerk() + k.getType();
                data[row][3] = k.getTahunPembuatan();
                ++row;
            }
            TableModel model = new DefaultTableModel(data, title);
            tblBrowseKendaraan.setModel(model);
            browseKendaraan.setSize(800, 600);
            browseKendaraan.getContentPane().setBackground(new java.awt.Color(51, 102, 255));
            browseKendaraan.setModal(true);
            browseKendaraan.setVisible(true);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }

    private void btnRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRefreshActionPerformed
        reloadAll();
    }//GEN-LAST:event_btnRefreshActionPerformed

    private void loadPerusahaan() {
        try {
            cmbPerusahaan.removeAllItems();
            for (Perusahaan p : pDao.getAllPerusahaan()) {
                cmbPerusahaan.addItem(p);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }

    private int getCmbPerusahaanIndex(Perusahaan p) {
        int index = 0;
        for (Perusahaan tmp : pDao.getAllPerusahaan()) {
            if (tmp.getId() == p.getId()) {
                break;
            }
            ++index;
        }
        return index;
    }

    private void bindKartuPengawasan() {
        try {
            String title[] = {"No.Kartu Pengawasan", "No. Ijin Trayek", "No. Kendaraan", "Masa Berlaku"};
            Object[][] data = new Object[listKartuPengawasan.size()][4];
            int row = 0;
            for (KartuPengawasanOtobisUmum k : listKartuPengawasan) {
                data[row][0] = k.getNomor();
                data[row][1] = k.getIjinTrayek().getNomor();
                data[row][2] = k.getArmada().getKendaraan().getNomorPolisi();
                data[row][3] = formater.format(k.getTanggalBerlakuMulai()) + " s/d "
                        + formater.format(k.getTanggalBerlakuSelesai());
                ++row;
            }
            TableModel model = new DefaultTableModel(data, title);
            tblKartu.setModel(model);
        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }

    private void tblIjinMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblIjinMouseClicked
        try {
            if (list.size() > 0 && tblIjin.getSelectedRow() > -1) {
                selected = list.get(tblIjin.getSelectedRow());
                txtNomor.setText(selected.getNomor());
                tglIjin.setDate(selected.getTanggal());
                cmbPerusahaan.setSelectedIndex(getCmbPerusahaanIndex(selected.getPerusahaan()));
                txtKartuPengawasan.setText(selected.getKartuPengawasan().getNomor());
                txtNoKendaraan.setText(selected.getKendaraan().getNomorPolisi());
                txtNoUjiBerkala.setText(selected.getNomorUjiBerkala());
                txtMasaUjiBerkala.setText(selected.getMasaBerlakuUjiBerkala());
                txtMaksud.setText(selected.getMaksudPerjalanan());
                txtKapasitas.setText(selected.getKapasitasTempatDuduk() + "");
                tglBerlakuSampai.setDate(selected.getBerlakuSampai());
                txtJumlah.setText(selected.getJumlahPenumpang() + "");
                txtRute.setText(selected.getRutePerjalanan());
                kendaraan = selected.getKendaraan();
                kartuPengawasan = selected.getKartuPengawasan();
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_tblIjinMouseClicked

    private void btnBrowseKendaraanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseKendaraanActionPerformed
        isCari = false;
        browseKendaraan();
    }//GEN-LAST:event_btnBrowseKendaraanActionPerformed

    private void btnBrowseKartuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseKartuActionPerformed
        try {
            listKartuPengawasan = kDao.getAllKartuPengawasanOtobisUmum();
            bindKartuPengawasan();
            browseKartuPengawasan.setSize(800, 600);
            browseKartuPengawasan.getContentPane().setBackground(new java.awt.Color(51, 102, 255));
            browseKartuPengawasan.setModal(true);
            browseKartuPengawasan.setVisible(true);
        } catch (Exception ex) {
            ex.printStackTrace();
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_btnBrowseKartuActionPerformed

    private void btnCariKartuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCariKartuActionPerformed
        try {
            listKartuPengawasan = kDao.getByNomor(txtNoKartuCari.getText());
            bindKartuPengawasan();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_btnCariKartuActionPerformed

    private void tblKartuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblKartuMouseClicked
        if (listKartuPengawasan.size() > 0 && tblKartu.getSelectedRow() > -1) {
            kartuPengawasan = listKartuPengawasan.get(tblKartu.getSelectedRow());
            txtKartuPengawasan.setText(kartuPengawasan.getNomor());
            browseKartuPengawasan.setVisible(false);
        }
    }//GEN-LAST:event_tblKartuMouseClicked

    private void btnSimpanActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSimpanActionPerformed
        try {
            if (!txtNomor.getText().isEmpty() && kendaraan != null && kartuPengawasan != null
                    && !txtNoUjiBerkala.getText().isEmpty() && !txtMasaUjiBerkala.getText().isEmpty()
                    && !txtMaksud.getText().isEmpty() && !txtKapasitas.getText().isEmpty()
                    && !txtJumlah.getText().isEmpty() && !txtRute.getText().isEmpty()) {
                if (selected == null) {
                    IjinInsidentil i = new IjinInsidentil();
                    i.setNomor(txtNomor.getText());
                    i.setTanggal(tglIjin.getDate());
                    i.setPerusahaan((Perusahaan) cmbPerusahaan.getSelectedItem());
                    i.setKendaraan(kendaraan);
                    i.setKartuPengawasan(kartuPengawasan);
                    i.setNomorUjiBerkala(txtNoUjiBerkala.getText());
                    i.setMasaBerlakuUjiBerkala(txtMasaUjiBerkala.getText());
                    i.setMaksudPerjalanan(txtMaksud.getText());
                    i.setKapasitasTempatDuduk(Integer.valueOf(txtKapasitas.getText()));
                    i.setBerlakuSampai(tglBerlakuSampai.getDate());
                    i.setJumlahPenumpang(Integer.valueOf(txtJumlah.getText()));
                    i.setRutePerjalanan(txtRute.getText());
                    dao.insert(i);
                    kendaraan = null;
                    kartuPengawasan = null;
                } else {
                    selected.setNomor(txtNomor.getText());
                    selected.setTanggal(tglIjin.getDate());
                    selected.setPerusahaan((Perusahaan) cmbPerusahaan.getSelectedItem());
                    selected.setKendaraan(kendaraan);
                    selected.setKartuPengawasan(kartuPengawasan);
                    selected.setNomorUjiBerkala(txtNoUjiBerkala.getText());
                    selected.setMasaBerlakuUjiBerkala(txtMasaUjiBerkala.getText());
                    selected.setMaksudPerjalanan(txtMaksud.getText());
                    selected.setKapasitasTempatDuduk(Integer.valueOf(txtKapasitas.getText()));
                    selected.setBerlakuSampai(tglBerlakuSampai.getDate());
                    selected.setJumlahPenumpang(Integer.valueOf(txtJumlah.getText()));
                    selected.setRutePerjalanan(txtRute.getText());
                    dao.update(selected);
                    kendaraan = null;
                    kartuPengawasan = null;
                    selected = null;
                }
                reloadAll();
                txtNomor.setText("");
                cmbPerusahaan.setSelectedItem(null);
                txtNoKendaraan.setText("");
                txtKartuPengawasan.setText("");
                tglIjin.setDate(new Date());
                txtNoUjiBerkala.setText("");
                txtMasaUjiBerkala.setText("");
                txtMaksud.setText("");
                txtKapasitas.setText("");
                tglBerlakuSampai.setDate(new Date());
                txtJumlah.setText("");
                txtRute.setText("");
                JOptionPane.showMessageDialog(this, "Data tersimpan");
                tabpane.setSelectedIndex(0);
            } else {
                JOptionPane.showMessageDialog(this, "Input Data dengan lengkap");
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
    }//GEN-LAST:event_btnSimpanActionPerformed

    private void btnBuatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuatActionPerformed
        txtNomor.setText("");
        cmbPerusahaan.setSelectedItem(null);
        txtNoKendaraan.setText("");
        txtKartuPengawasan.setText("");
        tglIjin.setDate(new Date());
        txtNoUjiBerkala.setText("");
        txtMasaUjiBerkala.setText("");
        txtMaksud.setText("");
        txtKapasitas.setText("");
        tglBerlakuSampai.setDate(new Date());
        txtJumlah.setText("");
        txtRute.setText("");
        selected = null;
        kendaraan = null;
        kartuPengawasan = null;
        txtNomor.requestFocus();
    }//GEN-LAST:event_btnBuatActionPerformed

    private void btnHapusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHapusActionPerformed
        if (selected != null) {
            dao.delete(selected);
            txtNomor.setText("");
            cmbPerusahaan.setSelectedItem(null);
            txtNoKendaraan.setText("");
            txtKartuPengawasan.setText("");
            tglIjin.setDate(new Date());
            txtNoUjiBerkala.setText("");
            txtMasaUjiBerkala.setText("");
            txtMaksud.setText("");
            txtKapasitas.setText("");
            tglBerlakuSampai.setDate(new Date());
            txtJumlah.setText("");
            txtRute.setText("");
            kendaraan = null;
            kartuPengawasan = null;
            reloadAll();
            JOptionPane.showMessageDialog(this, "Data terhapus");
        }
    }//GEN-LAST:event_btnHapusActionPerformed

    private void btnCetakActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCetakActionPerformed

        try {
            if (selected != null) {
                //ambil parameter
                Map mp = new HashMap();
                mp.put("nomor", selected.getNomor());

                DataSource ds = (DataSource) MainApps.appContext.getBean("dataSource");
                JDialog printView = new JDialog();
                JasperPrint print = JasperFillManager.fillReport("print/ijinInsidentil.jasper",
                        mp, ds.getConnection());
                JRViewer viewer = new JRViewer(print);
                printView.getContentPane().add(viewer);
                printView.setModal(false);
                printView.setTitle("Print Ijin Trayek");
                printView.setSize(800, 500);
                printView.setVisible(true);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(this, ex.getMessage());
        }
}//GEN-LAST:event_btnCetakActionPerformed

    private void mnuWarnaHeaderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuWarnaHeaderActionPerformed
        Color tmp = JColorChooser.showDialog(this, "Ganti Warna Header", headerPanel.getBackground());
        headerColor.setRgb(tmp.getRGB());
        wDao.update(headerColor);
        updateWarna();
    }//GEN-LAST:event_mnuWarnaHeaderActionPerformed

    private void mnuWarnaBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuWarnaBackActionPerformed
        Color tmp = JColorChooser.showDialog(this, "Ganti Warna Background", this.getContentPane().getBackground());
        backgroudColor.setRgb(tmp.getRGB());
        wDao.update(backgroudColor);
        updateWarna();
    }//GEN-LAST:event_mnuWarnaBackActionPerformed

    private void mnuWarnaDefaultActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuWarnaDefaultActionPerformed
        headerColor.setRgb(-16777012);
        backgroudColor.setRgb(-13408513);
        wDao.update(headerColor);
        wDao.update(backgroudColor);
        updateWarna();
    }//GEN-LAST:event_mnuWarnaDefaultActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDialog browseKartuPengawasan;
    private javax.swing.JDialog browseKendaraan;
    private javax.swing.JButton btnBrowseKartu;
    private javax.swing.JButton btnBrowseKendaraan;
    private javax.swing.JButton btnBuat;
    private javax.swing.JButton btnCariKartu;
    private javax.swing.JButton btnCariKendaraan;
    private javax.swing.JButton btnCariKendaraan1;
    private javax.swing.JButton btnCariNomor;
    private javax.swing.JButton btnCetak;
    private javax.swing.JButton btnHapus;
    private javax.swing.JButton btnRefresh;
    private javax.swing.JButton btnSimpan;
    private javax.swing.JComboBox cmbPerusahaan;
    private javax.swing.JPanel headerPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JMenu mnuUbahWarna;
    private javax.swing.JMenuItem mnuWarnaBack;
    private javax.swing.JMenuItem mnuWarnaDefault;
    private javax.swing.JMenuItem mnuWarnaHeader;
    private javax.swing.JTabbedPane tabpane;
    private javax.swing.JTable tblBrowseKendaraan;
    private javax.swing.JTable tblIjin;
    private javax.swing.JTable tblKartu;
    private org.jdesktop.swingx.JXDatePicker tglBerlakuSampai;
    private org.jdesktop.swingx.JXDatePicker tglIjin;
    private javax.swing.JTextField txtCariNomorPolisi;
    private javax.swing.JTextField txtJumlah;
    private javax.swing.JTextField txtKapasitas;
    private javax.swing.JTextField txtKartuPengawasan;
    private javax.swing.JTextField txtMaksud;
    private javax.swing.JTextField txtMasaUjiBerkala;
    private javax.swing.JTextField txtNoKartuCari;
    private javax.swing.JTextField txtNoKendaraan;
    private javax.swing.JTextField txtNoUjiBerkala;
    private javax.swing.JTextField txtNomor;
    private javax.swing.JTextField txtRute;
    // End of variables declaration//GEN-END:variables
}
